﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using InHD.model;
using InHD.commands;
using System.Windows.Input;

namespace InHD.viewmodels
{
    class CustomerListViewModel:WorkspaceViewModel
    {

        #region Value Property
        private List<Customer> _customerRowCollection;
        private int _rowIndex = -1;
        public string commandExcute = string.Empty;
        private Customer _customer;
        #endregion

        #region Constructor
        public CustomerListViewModel( List<Customer> listCustomer)
        {
            _customerRowCollection = listCustomer;
        }
        #endregion

        #region Presentation Property
        public List<Customer> CustomerRowCollection
        {
            get
            {
                return _customerRowCollection;
            }
            set
            {
                if (_customerRowCollection != value)
                {
                    _customerRowCollection = value;
                    OnPropertyChanged("CustomerRowCollection");
                }
            }
        }

        public int RowIndex
        {
            get
            {
                return this._rowIndex;
            }
            set
            {
                this._rowIndex = value;
                OnPropertyChanged("RowIndex");
            }
        }

        public Customer SelectedCustomer
        {
            get
            {
                return this._customer;
            }
            set
            {
                if (value != null)
                {
                    this._customer = value;
                }
            }
        }
        #endregion

        #region Command 
        private RelayCommand _viewCustomerCommand;
        public ICommand ViewCustomerCommand
        {
            get
            {
                if (_viewCustomerCommand == null)
                {
                    _viewCustomerCommand = new RelayCommand(
                        (param) => this.ViewCustomer(), (param) => this.CanView);
                }
                return _viewCustomerCommand;
            }
        }

        private RelayCommand _addNewCustomerCommand;
        public ICommand AddNewCustomerCommand
        {
            get
            {
                if (_addNewCustomerCommand == null)
                {
                    _addNewCustomerCommand = new RelayCommand(
                        (param) => this.AddNewCustomer());
                }
                return _addNewCustomerCommand;
            }
        }
        #endregion

        #region Command Method
        void ViewCustomer()
        {
            commandExcute = "View";
            OnRequestClose();
        }

        void AddNewCustomer()
        {
            commandExcute = "Add";
            OnRequestClose();
        }
        #endregion

        public bool CanView { get { return (this.SelectedCustomer == null) ? false : true; } }
    }
}
